package com.chen.controller;

import com.chen.entity.Test;
import com.chen.service.impl.TestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private TestServiceImpl testService;

    /**
     * 从从库查询
     *
     * @return
     */
    @GetMapping("/listBySlave")
    public List<Test> listBySlave() {
        return testService.getTestsFromSlave();
    }

    /**
     * 从主库查询
     *
     * @return
     */
    @GetMapping("/listByMaster")
    public List<Test> listByMaster() {
        return testService.getTestsFromMaster();
    }

    /**
     * 从主库插入
     *
     * @return
     */
    @GetMapping("/addByMaster")
    public String addByMaster() {
        Test test = new Test();
        test.setId(11);
        test.setName("test11");
        int row = testService.add(test);
        String res = "添加Test成功,添加行数：" + row;
        System.out.println(res);
        return res;
    }
}
